from django.db import models

# Create your models here.
class Buyer(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32)
    password = models.CharField(max_length=32)

class Address(models.Model):
    id = models.AutoField(primary_key=True)
    receiver = models.CharField(max_length=32)
    address = models.CharField(max_length=128)
    phone = models.CharField(max_length=32)
    buyer = models.ForeignKey(to='Buyer', on_delete=models.CASCADE)

class BuyCar(models.Model):
    goods_id = models.IntegerField()
    goods_name = models.CharField(max_length=32)
    goods_price = models.FloatField()
    goods_num = models.IntegerField()
    goods_picture = models.CharField(max_length=64)
    buyer = models.ForeignKey(to='Buyer', on_delete=models.CASCADE)


class Order(models.Model):
    order_num = models.CharField(max_length=32)
    order_time = models.DateTimeField()
    order_status = models.CharField(max_length=32)
    order_total = models.FloatField()
    buyer = models.ForeignKey(to='Buyer', on_delete=models.CASCADE)
    address = models.ForeignKey(to='address', on_delete=models.CASCADE)


    def __str__(self):
        return "Order object:{}--{}-{}-{}".format(self.pk, self.order_num, self.order_time,
                                                  self.order_status, self.order_total, self.buyer, self.address)

class OrderGoods(models.Model):
    goods_id = models.IntegerField()
    goods_name = models.CharField(max_length=32)
    goods_price = models.FloatField()
    goods_num = models.IntegerField()
    goods_picture = models.CharField(max_length=64)
    order = models.ForeignKey(to='Order', on_delete=models.CASCADE)

    def __str__(self):
        return "OrderGoods object:{}--{}-{}-{}".format(self.goods_id,self.goods_name,self.goods_price,self.goods_num)

class GoodsComments(models.Model):
    comment_state = models.IntegerField()
    comment_statement = models.CharField(max_length=50)
    comment_time = models.DateTimeField()
    buyer = models.ForeignKey(to='Buyer', on_delete=models.CASCADE)
    goods = models.ForeignKey(to='Seller.Goods', on_delete=models.CASCADE)

    def __str__(self):
        return "GoodsComments object:{}--{}-{}-{}".format(self.comment_state, self.comment_statement, self.comment_time, self.buyer)

class GoodsCollect(models.Model):
    collect_state = models.IntegerField()
    buyer = models.ForeignKey(to='Buyer', on_delete=models.CASCADE)
    goods = models.ForeignKey(to='Seller.Goods', on_delete=models.CASCADE)

    def __str__(self):
        return "GoodsCollect object:{}--{}-{}".format(self.collect_state, self.buyer, self.goods)


